package hypermediaresearch.controller.hypermedia;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/*
 * VinhJune 2012
 */
import hypermediaresearch.model.Partner;
import hypermediaresearch.service.PartnerService;
import hypermediaresearch.service.ProjectService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class All_partnersController extends Controller {

    private PartnerService ptnService = new PartnerService();
    private ProjectService prjService = new ProjectService();
    
    @Override
    public Navigation run() throws Exception {
        
        String name = requestScope("name");
        List<Partner> partnerList = new ArrayList<Partner>();
        if (name != null) {
            partnerList = prjService.getPartnersByProject(name);
            requestScope("partnerList", partnerList);
        } else {
            partnerList = ptnService.getPartnerList();
            for (Iterator iterator = partnerList.iterator(); iterator.hasNext();) {
                Partner partner = (Partner) iterator.next();
                if (partner.getDescription().length() > 256)
                    partner.setDescription(partner.getDescription().substring(0, 255));
            }
        }
        requestScope("partnerList",partnerList);
        requestScope("project", name);
        return forward("all_partners.jsp");
    }
}
